#ifndef DECODER_H
#define DECODER_H

#include <vector>
#include <string>

namespace qrcode{

typedef std::vector<std::pair<std::vector<std::vector<int>>, std::vector<std::vector<int>>>> datapairs;
typedef std::pair<std::vector<std::vector<int>>, std::vector<std::vector<int>>> datapair;

class Decoder
{
private:
    std::string imagefile;

    std::string dataInfo;
    char errorlevel;
    int maskNum;
    int version;
    std::string mode;
    int dataLength;
    int count; //字符计数指示符的位数

    std::vector<std::vector<int>> ToCodewords(std::vector<int> &bits);
    void RemoveRemainderBits(std::vector<int> &databits, int length);
    datapairs HandleDataBits(std::vector<int> databits);
    void RemovePadBits(std::vector<std::vector<int>> &data);
    bool IsPadBits(std::vector<int> &data);
    void GetDataLength(std::vector<int> &databits, int x);

    void RecoveryDataNUM(std::vector<int> &databits);
    void RecoveryDataAN(std::vector<int> &databits);
    void RecoveryDataByte(std::vector<int> &databits);
    void RecoveryDataECI(std::vector<int> &databits);

    char ToChar(int x);
    std::string ToIntStr(std::vector<int> vec);
    std::string ToANStr(std::vector<int> vec);
    std::string ToByteStr(std::vector<int> vec);
    char ToUnicodeStr(std::vector<int> vec);

public:
    Decoder();
    void Decoding();

    void DecodeData(std::vector<int> databits);
    void DecodeFormat(std::vector<int> format);
    void DecodeVersion(std::vector<int> ver);

    void setImagefile(std::string value);
};

}

#endif // DECODER_H
